<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>

    <link rel="stylesheet" href="dist/css/swiper-bundle.min.css">
    <script src="dist/js/swiper-bundle.min.js"></script>
    <style>
        .swiper-container {
            width: 600px;
            height: 300px;
        }
    </style>
</head>

<body>
    <div id="box">
        <div class="swiper-container kerwin">
            <div class="swiper-wrapper">
                <div class="swiper-slide" v-for="(data, index) in datalist"v-swiper="{
                    current: index,
                    length: datalist.length
                }">
                    {{data}}
                </div>
            </div>
            <div class="swiper-pagination"></div>
        </div>
    </div>

        <script type="text/javascript">
            Vue.directive("swiper", {
                inserted(el, binding,vnode){
                    console.log(vnode.context) //context是当前节点所在的组件对象

                    if(binding.value.current===binding.value.length-1){
                        new Swiper(".kerwin",{
                            loop: true, 
                            pagination: {
                                el: '.swiper-pagination',
                            },
                        })
                    }
                }
            })

            var vm = new Vue({
                el: "#box",
                data: {
                    datalist: [],
                },
                mounted() {
                    setTimeout(() => {
                        this.datalist = ["111", "222", "333", "444", "555", "666"]
                    }, 2000)
                }
            })
        </script>
</body>

</html>